<?php

namespace brand\logic;

use surface\Factory;
use think\facade\Db;

class Config
{

    /**
     * 默认控制器路径
     */
    public static $controller_path = 'app/admin/controller/';

    /**
     * 默认模型路径
     */
    public static $model_path = 'app/common/model/';

    /**
     * 默认验证器路径
     */
    public static $validate_path = 'app/common/validate/';

    /**
     * 插件名称
     */
    public static $addon_name = '';

    const STUB_PATH = 'extend/brand/stubs/';
    const STUB_SUFFIX = '.stub';

    /**
     * 默认语言包路径
     */
    const LANG_PATH = '';

    /**
     * 默认CURD配置路径
     */
    public static $curd_path = 'extend/brand/tables/';
    const CURD_SUFFIX = '.josn';
    public static $CURD_BACKUPS_PATH = 'extend/brand/tables/backups/';
    const CURD_IS_BACKUPS = false;

    /**
     * 默认Brand组件命名空间
     */
    const BRAND_NAMESPACE = "brand\components\\";

    const BRAND_BUILD_NAMESPACE = "\\brand\\build\\";

    /**
     * 数据库名字位置
     */
    const DATABASE_CONFIG_LOCATION = 'connections.mysql.database';

    /**
     * 数据表前缀位置
     */
    const PREFIX_CONFIG_LOCATION = 'connections.mysql.prefix';

    /**
     * 去除默认表
     */
    const DEFAULT_DATABASE = ['auth_group_access'];

    /**
     * 自动写入时间
     */
    const CREATE_TIME = 'create_time';
    const UPDATE_TIME = 'update_time';
    const DELETE_TIME = 'delete_time';

    const NO_CURD_CONTROLLER = ['Index','Curd'];

    const ARRAY_DIVISION = ',';
    const ARRAY_DIVISION_TIME = ' 至 ';

    const TABLE_SHOW_TYPE = [
        'curd'  =>  'CURD自动转换(特定字段可自动生成行编辑/时间格式)',
        'options'   =>  '单选/多选/下拉框/开关 自定义显示(根据options值显示)',
        'default'   =>  '原样输出'
    ];

    const SPECIAL_TYPE = [
        'province'  =>  '省',
        'city'  =>  '市',
        'area'  =>  '区',
        'province_id'  =>  '省',
        'city_id'  =>  '市',
        'area_id'  =>  '区',

    ];


    //分页数量
    public static $page_size = 10;
    //默认顶部按钮
    public static $header_buttons = ['add','delete','search','export'];
    //默认右侧按钮
    public static $right_buttons = ['edit','delete'];

    public static $is_async = true;
    public static $page_limit = 10;
    public static $stat_html = 1;
    public static $button_event = [
        'page' => '页面 page',
        'submit' => '提交 submit',
        'confirm' => '确认 confirm',
        'refresh' => '刷新 refresh',
        'null' => '无功能 null',
    ];

    /**
     * 获取混入模板
     * @param $name
     * @return false|string
     */
    public static function getMixinPath($name)
    {
        return __DIR__. DIRECTORY_SEPARATOR. '..' . DIRECTORY_SEPARATOR . 'mixin' . DIRECTORY_SEPARATOR . $name . '.html';
    }

    public static function getBrandList()
    {
        return [
            'Input' => 'Input输入框',
            'Date' => 'Date日期',
            'Time' => 'Time时间',
            'Radio' => 'Radio单选按钮',
            'Select' => 'Select下拉框',
            'Checkbox' => 'CheckBox多选',
            'Upload' => 'Upload文件上传',
            'Editor' => 'Editor编辑器',
            'Number' => 'Number数字输入框',
            'Take' => 'Take关联数据表',
            'Switcher' => 'Switcher开关',
            'Arrays' => 'Arrays自定义数组',
            'Color' => 'Color颜色',
            'Hidden' => 'Hidden隐藏显示',
            'Rate' => 'Rate评分',
            'Slider' => 'Slider数字选择器',
        ];
    }

    public static function getConditionList()
    {
        return[
            0 => "不搜索",
            '=' =>  "=",
            '>' =>  ">",
            '>=' =>  ">=",
            '<' =>  "<",
            '<=' =>  "<=",
            'like' =>  "模糊搜索",
            'between' =>  "区间搜索",
            'in' =>  "In",
            'notin' =>  "NotIn",
        ];
    }

    public static $add_script = [];
    public static $add_from_script = [];
    public static $add_table_script = [];
    public static $add_style = [];

    public static function FactoryConfig()
    {

        $table_script = [
            '<script src="/static/backend/js/excel.min.js"></script>'
        ];
        $from_script = [
            '<script src="/static/backend/js/mixin/form.js"></script>'
        ];


        $add_table_script = array_merge($table_script,self::$add_table_script,self::$add_script);
        $add_from_script = array_merge($from_script,self::$add_from_script,self::$add_script);

        self::$add_from_script = $add_from_script;
        self::$add_table_script = $add_table_script;

        $style = [
            '<link href="/static/backend/css/brand.css?c='.time().'" rel="stylesheet"> '
        ];
        $style = array_merge($style,self::$add_style);


        Factory::configure(
            [
                // 静态资源CDN地址 默认使用公共cdn 如果需要自定义cdn地址 请下载静态资源 https://gitee.com/iszsw/surface-src
                'cdn'   => '/static/surface-src',
                'table' => [
                    'style'   => $style, // table全局样式
                    'script'  => $add_table_script, // table全局脚本
                    'globals' => [ // table全局配置
                        'props' => [
                            'emptyText' => "暂无数据~",
                            'stripe'    =>  true,
                            'size'      =>  'medium',
                            'border'      =>  false,
                            'border'      =>  false,
                        ],
                    ],
                    // ... 组件
                ],
                'form'  => [
                    'style'   => $style, // form全局样式
                    'script'  => $add_from_script, // form全局脚本
                    'globals' => [ // form全局配置
                        'props' =>  [
                            'size'  =>  'medium',
                            'async'    => [
                                    'url' => '',
                                ],
                            'label-width'   =>  '10vw'
                        ],
                        'async' => [
                            'url' => '',
                        ]
                    ],

                    // ... 组件
                ],
            ]
        );
    }



    public static function getUploadUrl()
    {
        ;
        return url(BrandHelper::getAdminName().'/attachment.attachment/upload')->build();
    }

    public static function getManageUrl()
    {
        return url(BrandHelper::getAdminName().'/attachment.attachment/manage')->build();
    }

    public static function buttonName($name)
    {
        switch ($name){
            case 'add':
                return '新增';
            case 'edit':
                return '修改';
            case 'delete':
                return '删除';
            case 'search':
                return '搜索';
            case 'export':
                return '导出';
            case 'import':
                return '导入';
            default:
                return $name;
        }
    }





}